package com.ouc.service.impl;

import com.ouc.entity.Circle;
import com.ouc.entity.Rectangle;
import com.ouc.entity.Shape;
import com.ouc.entity.Triangle;
import com.ouc.mapper.ShapeMapper;
import com.ouc.service.ShapeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Name: ShapeServiceImpl
 * @Description:
 * @Author: Mr.Tong
 */

@Service
public class ShapeServiceImpl implements ShapeService {

    @Autowired
    private ShapeMapper shapeMapper;

    @Override
    public Shape insertShape(Shape shape) {
        if (shape instanceof Circle) {
            shapeMapper.insertCircleInfo((Circle) shape);
        } else if (shape instanceof Rectangle) {
            shapeMapper.insertRectangleInfo((Rectangle) shape);
        } else if (shape instanceof Triangle) {
            shapeMapper.insertTriangleInfo((Triangle) shape);
        }
        return shape;
    }

    @Override
    public Shape getShapeById(Integer id) {
        return shapeMapper.getShapeById(id);
    }

    @Override
    public Boolean deleteShapeById(Integer id) {
        return shapeMapper.deleteShapeById(id);
    }

    @Override
    public Shape getShapeByShapeCode(String shapeCode) {
        return shapeMapper.getShapeByShapeCode(shapeCode);
    }

    @Override
    public List<Shape> getAllShape() {
        return shapeMapper.getAllShape();
    }

    @Override
    public Boolean shapeExists(String shapeCode) {
        return this.getShapeByShapeCode(shapeCode) != null;
    }
}

